package com.xwj.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ConsumerService {

    /**
     * 集群模式并发消费同步发送的消息
     */
    @Service
    @RocketMQMessageListener(topic = "syncSendMsg_topic", consumerGroup = "ConsumerSyncSend_Group_1")
    public class ConsumerSyncSend implements RocketMQListener<String> {
        @Override
        public void onMessage(String msg) {
            log.info("消费同步消息：{}", msg);
        }
    }

    /**
     * 集群模式并发消费异步发送的消息
     */
    @Service
    @RocketMQMessageListener(topic = "asyncSendMsg_topic", consumerGroup = "ConsumerSyncSend_Group_2")
    public class ConsumeAsyncSend implements RocketMQListener<String> {
        @Override
        public void onMessage(String msg) {
            log.info("消费异步消息：{}", msg);
        }
    }

    /**
     * 集群模式顺序消费异步发送的消息
     */
    @Service
    @RocketMQMessageListener(topic = "asyncSendOrderly_topic", consumerGroup = "ConsumerSyncSend_Group_2", consumeMode = ConsumeMode.ORDERLY)
    public class ConsumeAsyncOrderlySend implements RocketMQListener<String> {
        @Override
        public void onMessage(String msg) {
            log.info("顺序消费异步消息：{}", msg);
        }
    }

    /**
     * 广播模式并发消费异步发送的消息
     */
    @Service
    @RocketMQMessageListener(topic = "asyncSendMsg_topic", consumerGroup = "ConsumerSyncSend_Group_3", messageModel = MessageModel.BROADCASTING)
    public class BroadcastingConsumeAsyncSend implements RocketMQListener<String> {

        @Override
        public void onMessage(String message) {
            log.info("广播模式消费异步消息：{}", message);
        }
    }
}
